//
//  STMPinAnnotationView.m
//  StationManager
//
//  Created by 泽华伟业 on 17/3/4.
//  Copyright © 2017年 Helong. All rights reserved.
//
/*
自定义的大头针
 */
#import "STMPinAnnotationView.h"

@implementation STMPinAnnotationView
- (instancetype)init
{
    self = [super init];
    if (self) {

    }
    return self;
}

//站名Label
- (UILabel *)nameLbel{
    if (!_nameLbel) {
        _nameLbel = [[UILabel alloc]init];
        [self addSubview:_nameLbel];
        //设置居中对齐
        [_nameLbel setTextAlignment:NSTextAlignmentCenter];
        [_nameLbel setFont:[UIFont systemFontOfSize:8]];
        [_nameLbel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_bottom);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(100*wl, 10*hl));
        }];
    }
    return _nameLbel;
}
//显示温度或者降雨量lable
- (UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc]init];
        [_contentLabel setTextColor:[UIColor redColor]];
        [_contentLabel setTextAlignment:NSTextAlignmentCenter];
        [self addSubview:_contentLabel];
        [_contentLabel setFont:[UIFont systemFontOfSize:8]];
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.mas_top);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(38*wl, 10*hl));
        }];
    }
    return _contentLabel;
}


-(UILabel *)typeLabel{
    
    if (!_typeLabel) {
        
        _typeLabel = [[UILabel alloc] init];
        _typeLabel.textAlignment = NSTextAlignmentCenter;
        _typeLabel.font = [UIFont systemFontOfSize:9];
        [self addSubview:_typeLabel];
        [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.left.right.equalTo(self);
        }];
    }
    return _typeLabel;
}

- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]init];
        [self addSubview:_imageView];
        [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.left.right.equalTo(self);
        }];
    }
    return _imageView;
}

//扩大大头针的点击范围，改善用户体验
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    CGRect rect = CGRectZero;
    rect.size.width = self.bounds.size.width + 10;
    rect.size.height = self.bounds.size.height +10;
    return CGRectContainsPoint(rect, point);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
